#include<iostream>
#include<map>
#include<string>
#include<cstring>
using namespace std;
const int N = 110;
map<string, bool>mp;
string s1, s2, s12;
int main()
{
	int t, n;
	cin >> t;
	int k = 0;
	while (t--) {
		mp.clear();
		k++;
		cin >> n;
		cin >> s1;
		cin >> s2;
		cin >> s12;
		int step = 0;
		while (1) {
			string temp = "";
			int n1 = 0;
			for (int i = 0; i < n; i++) {
				temp += s2[i];
				temp += s1[i];
			}
			step++;
			if (temp == s12) {
				cout << k << " " << step << endl;
				break;
			}
			if (mp[temp] == 1) {
				cout << k << " " << -1 << endl;
				break;
			}
			mp[temp] = 1;
			s1 = "";
			s2 = "";
			s1 = temp.substr(0, n);
			s2 = temp.substr(n, n);
			/*for (int i = 0; i < n1; i++) {
				cout << temp[i];
			}
			cout << endl;*/
		}
	}
	return 0;
}